package org.hackystat.ui.projectviewer.gwt.client.widgets;

import org.hackystat.ui.projectviewer.gwt.client.CSSStyles;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Provides title panel for all Pane type panels.
 *
 * @author Pavel Senin.
 *
 */
public class PanelTitleWidget extends Composite {

  private final HorizontalPanel outer = new HorizontalPanel();

  private final HorizontalPanel titleColumns = new HorizontalPanel();

  private final VerticalPanel titleRows = new VerticalPanel();
  // private final Label mainTitle = new Label();
  private final HTML mainTitle = new HTML();
  // private final Label subTitle = new Label();
  private final HTML subTitle = new HTML();

  /** {@literal} SMALL_WAIT_IMAGE icon. */
  public static final String SMALL_WAIT_IMAGE = "images/wait-animated-16.gif";
  final Image waitImage = new Image(SMALL_WAIT_IMAGE);

  /**
   * Constructor.
   */
  public PanelTitleWidget() {

    outer.setStyleName(CSSStyles.PTW_OUTER);

    waitImage.setStyleName(CSSStyles.CP_IMAGE);
    subTitle.setStyleName(CSSStyles.PTW_IMAGE);
    // waitImage1.setStyleName("waitimage-Small");

    mainTitle.setStyleName(CSSStyles.PTW_MAIN_TITLE);
    titleRows.add(mainTitle);
    subTitle.setStyleName(CSSStyles.PTW_SUB_TITLE);
    titleRows.add(subTitle);

    titleColumns.add(titleRows);

    outer.add(titleColumns);

    initWidget(outer);
  }

  /**
   * Removes all images and sets single main title.
   *
   * @param title The main title text.
   */
  public void setSingleTitle(String title) {
    if (titleColumns.getWidgetCount() > 1) {
      titleColumns.remove(0);
    }
    subTitle.setText("");
    mainTitle.setText(title);
  }

  /**
   * Sets the wait image on or off.
   *
   * @param set The set parameter, true == image on, false == off.
   */
  public void setWait(boolean set) {
    if (set && titleColumns.getWidgetCount() < 2) {
      titleColumns.insert(waitImage, 0);
    }

    if (!set && titleColumns.getWidgetCount() > 1) {
      titleColumns.remove(0);
    }
  }

  /**
   * Sets the text for main title.
   *
   * @param title The title text.
   */
  public void setMainTitle(String title) {
    mainTitle.setText(title);
  }

  /**
   * Sets the subtitle.
   *
   * @param subTite The subtitle text to set.
   */
  public void setSubTitle(String subTite) {
    subTitle.setText(subTite);
  }

}
